<?php

namespace App\Http\Controllers\Admin\Pages;

use App\Facades\DeviceService;
use App\Facades\UserService;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

class UserController extends Controller
{
    public function index(Request $request)
    {
        $adminInfoList = UserService::getAllAdminInfo();
        return view('admin/index')->with([
            'admin_infos' => $adminInfoList,
            ]);
    }

    public function login(Request $request)
    {
        return view('admin/login');
    }
    
    //用户信息
    public function customers(Request $request)
    {
        $condition = $this->fomatParam($request->condition);
        $deviceType = $this->fomatParam($request->device_type);
        if($deviceType == '全部'){
            $deviceType = '';
        }
        $cutomers = UserService::findUserInfoWithDeviceCodeAndDeviceType($condition, $deviceType);
        $deviceTypes = DeviceService::getALLType();
        return view('admin/customers')->with([
            'customer_list' => $cutomers,
            'condition' => $request->condition,
            'device_type' => $request->device_type,
            'device_types' => $deviceTypes,
            ]);
    }

    private function fomatParam($param)
    {
        $param = str_replace('%', '\%', $param);
        return str_replace('_', '\_', $param);
    }

}
